# coding: utf-8
# from Crypto.Cipher import AES

from django.db import models
from django.utils import timezone
from django.conf import settings
from common.models.base import BaseModel
from common.models.position import JPositionCounty, JPositionTown, JPositionVillage
from common.models.user import User


class Bottle(BaseModel):
    """ 漂流瓶 """
    sender = models.ForeignKey(User)
    content = models.CharField(max_length=500, default='')
    is_del = models.NullBooleanField(default=False)

    def __unicode__(self):
        return self.content

    class Meta:
        app_label = 'common'
        db_table = 'fun_bottle'

    @property
    def reply_count(self):
        """ 回复数 """
        return self.bottlereplytrace_set.count()


class BottleGetTrace(BaseModel):
    """ 捞漂流瓶记录 """
    getter = models.ForeignKey(User)
    bottle = models.OneToOneField(Bottle)
    is_del = models.NullBooleanField(default=False, verbose_name=u'是否被捞瓶子的人删除了')

    def __unicode__(self):
        return self.bottle.content

    class Meta:
        app_label = 'common'
        db_table = 'fun_bottle_get_trace'
        unique_together = (('getter', 'bottle'),)


class BottleReplyTrace(BaseModel):
    user = models.ForeignKey(User)
    bottle = models.ForeignKey(Bottle)
    content = models.CharField(max_length=500, default='')

    def __unicode__(self):
        return self.content

    class Meta:
        app_label = 'common'
        db_table = 'fun_bottle_reply_trace'

